package top.roadvast.springboot.log.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import top.roadvast.springboot.log.response.JsonResult;
import top.roadvast.springboot.log.service.OrderOperateService;
import top.roadvast.springboot.log.utils.LogTemplate;

import javax.annotation.Resource;

/**
 * @Author 郭泽鹏
 * @Date 2021/10/10 0:25
 * @Version 1.0
 * @Description
 */
@Slf4j
@RestController
public class OrderOperateController {

    @Autowired
    @Qualifier(value = "logTemplate")
    private LogTemplate logTemplate;

    @Resource(name = "orderOperateServiceImpl")
    OrderOperateService orderOperateService;


    @PostMapping(value = "/createOrder")
    public String createOrder(@RequestBody(required = false) Object request) throws Exception {
        JsonResult response = null;
//        try {
        String order = orderOperateService.createOrder(request);
        return order;
//            response = JsonResult.success(orderCreateRsp);
//        }
//        catch (Exception e) {
//            msg = e.getMessage();
//            log.error(methodName+",userId:"+backendId+",request:"+ JSON.toJSONString(request),e);
//            throw new BizException(0,"下单失败");
//        }
//        finally {
//            logTemplate.setLog(methodName, msg, traceId, backendId, request, response, beginTime);
//            long endTime = System.currentTimeMillis();
//            LogObject logObject = new LogObject();
//            logObject.setEventName(methodName)
//                    .setMsg(msg)
//                    .setTraceId(traceId)
//                    .setUserId(backendId)
//                    .setRequest(request)
//                    .setResponse(response)
//                    .setCostTime((endTime - beginTime));
//            log.info(JSON.toJSONString(logObject));
//        }

//        return response;
    }
}
